{% extends 'base.html' %}

{% block style %}
    <style>
        img{
            width: 100%;
            height:100%;
        }
        .container {
            border: 1px solid black;
            background-color: white;
        }
        .jumbotron{
            padding: 0 0 0 0;
            background-color: white;
            margin-bottom: 0;
        }
        .container .jumbotron, .container-fluid .jumbotron {
            padding-right: 0;
            padding-left: 0;
        }
        @media (min-width: 768px) {
          .container {
            max-width: 540px;
          }
        }
        .pull-right {
            width: 100%;
        }
        .pull-right li {
            width: 33%;
            height: 100%;
            text-align: center;
            font-size: 20px;
        }
        .nav-pills > li+li{
            margin-left: 0;
        }
        .pull-right li:first-child{
            border-right: 1px solid lightgrey;
            border-bottom: 5px solid #d7736b;
        }
        .pull-right li:nth-child(2){
            border-right: 1px solid lightgrey;
            border-bottom: 5px solid #4587c0;
            border-right: 0;
        }
        .pull-right li:last-child{
            border-left: 1px solid lightgrey;
            border-bottom: 5px solid #685c89;
        }
        .titles-s {
            font-size: 24px;
            padding-top: 5px;
            font-weight: 700;
            color: #888888;
        }
        .titles-l {
            color: #8e9899;
            font-size: 18px;
        }
        .header{
            height: 85px;
            padding-bottom: 10px;
            border-bottom: 0;
        }
        @media screen and (min-width: 768px) {
          /* Remove the padding we set earlier */
          .header,
          .marketing,
          .footer {
            padding-right: 0;
            padding-left: 0;
          }
          .header {
            margin-bottom: 20px;
          }
          .jumbotron {
            border-bottom: 0;
          }
        }

        .tj_y{
            text-align: center;
            font-size: 24px;
            color: #666766;
            padding-bottom: 4px;
        }
        .common {
            text-align: center;
            padding-top: 10px;
            width: 90%;
            margin: 0 auto;
        }
        .row p:nth-child(3){
            padding-top: 0;
        }
        .row p:nth-child(11){
            font-size: 18px;
            color: #666667;
        }
        .from_main{
            width: 100%;
            margin-top: 20px;
            color: #666667;
        }
        .items_common{
            margin: 10px auto;
        }
        .reward {
            color: #666667;
            font-size: 20px ;
            font-weight: 700;
        }
        .rewards {
            color: black;
            font-size: 20px ;
            font-weight: 700;
        }

    </style>
{% endblock %}

{% block content %}
    <div class="container">
        <div class="header">
          <ul class="nav nav-pills pull-right">
            <li><p class="titles-s">0</p><p class="titles-l">You Entries</p></li><!---->
            <li><p class="titles-s">{{ people_number }}</p><p class="titles-l">Totals Entries</p></li><!---->
            <li id="timer">
                <p class="titles-s" id="day-time"></p>
                <p class="titles-l" id="time-list"></p>
            </li>
          </ul>
      </div>
      <div class="tj_y">
          <span style="color: red">Congratulations!</span>
      </div>
      <div class="jumbotron">
          <img src="/static/images/banner.png" alt="banner.png">
      </div>
      <div class="row">
          <p class="common reward">Congratulations in your winning</p>
          <p class="common rewards">Please transfer BNB to this BSC address:</p>
          <p class="common rewards">{{ contract_address }}</p>
          <p class="common reward">The system will adjust your allocation proportion according to the BNB you send</p>
          <p class="common reward">The white list will issue tokens 20% below the opening price</p>
      </div>

      <div class="from_main">
          <form class="form-inline" id="form_d" action="/k_page/" method="post">
              <div class="items_common">
                  <div class="form-group">
                    <label for="username" style="margin-right: 5px">Receive BSC address:</label>
                    <input type="email" class="form-control" id="username" alt="请填写该字段" name="telegram_username" placeholder="Receive BSC address">
                  </div>
                  <span style="margin-left: 60px">Reqiured</span>
              </div>
              <div class="items_common">
                  <div class="form-group">
                    <label for="bep" style="margin-right: 55px">email Address:</label>
                    <input type="email" class="form-control" id="bep" alt="请填写该字段" name="bep_wallet_address" placeholder="email Address">
                  </div>
                  <span style="margin-left: 60px">Reqiured</span>
              </div>
              <div style="text-align: center; color: red; padding-top: 5px;font-size: 20px" id="tas">

              </div>
              <hr>
              <div style="margin: 0 auto; text-align: center; padding-bottom: 10px">
                  <button type="button" class="btn btn-primary btn-block" id="commits">Commit</button>
              </div>
        </form>
      </div>


      <footer class="footer">
        <p>&copy; 2016 Company, Inc.</p>
      </footer>

    </div> <!-- /container -->
{% endblock %}


{% block js %}
    <script>
            function getTime(val) {
                var d,h,m,s,timeText;
                var oP = $('#time-list');
                setInterval(function(){
                    val--;
                    d = parseInt(val /(24*3600));
                    h = parseInt(val/60/60%24);
                    m = parseInt(val/60%60);
                    s = parseInt(val%60);
                    s = s < 10 ? "0" + s : s ;
                    timeText = h +"时" + m + "分" + s + "秒";
                    oP.text(timeText)
                    $('#day-time').text(d + "天");
                },1000)
            }

            if({{ left_time }} > 0 ) {
                getTime({{ left_time }})
            } else {
                $('#day-time').text("0天");
                $('#time-list').text("00时00分00秒");
            }

            function getQueryString(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }

            console.log(getQueryString('user_id'))

            $("#commits").click(function (){

            var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
                if(reg.test($('#bep').val())){

                   $.ajax({
                       url: '/k_page/?user_id=' + getQueryString('user_id'),
                       method: 'POST',
                       data: {
                           'a': $('#username').val(),
                           'b': $('#bep').val(),
                       },
                       success: function (res){
                            if (res.code === 200){
                                $("#tas").text(res.msg)
                                setInterval(function (){
                                    location.href = '/index/'
                                }, 3000)
                            }
                       }
                   })
                }else {
                    $("#tas").text("wrong email").css("color", 'red')
                    return
                }

            })
    </script>
{% endblock %}